package org.cargloss.cp.controller.modul.user;

import org.cargloss.cp.model.User;

import util.hibernate.DAO;

import com.opensymphony.xwork2.ActionSupport;

public class ActionCrud extends ActionSupport {
	private static final long serialVersionUID = -5933849517817526086L;
	private String id;
	private String userName;
	private String password;

	public String insert() {
		DAO<Integer> dao = new DAO<Integer>();
		User object = new User();
		object.setUserName(getUserName());
		object.setPassword(getPassword());
		dao.insert(object);
		dao.close();
		return "empty";
	}

	public String update() {
		DAO<Integer> dao = new DAO<Integer>();
		
		User object = (User) dao.find(User.class, Integer.valueOf(getId()));
		
		object.setUserName(getUserName());
		object.setPassword(getPassword());
		
		dao.update(object);
		dao.close();
		return "empty";
	}

	public String delete() {
		DAO<Integer> dao = new DAO<Integer>();
		User delete = (User) dao.find(User.class, Integer.valueOf(getId()));
		dao.delete(delete);
		dao.close();
		return "empty";
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
